package com.ustc.hewei.snowflakemodule.snowFlake;

import com.ustc.hewei.commonmodule.utils.Snowflake;
import com.ustc.hewei.snowflakemodule.segment.entity.SegmentAlloc;
import com.ustc.hewei.snowflakemodule.segment.service.ISegmentAllocService;
import com.ustc.hewei.snowflakemodule.util.Constants;
import com.ustc.hewei.snowflakemodule.util.IpUtils;
import com.ustc.hewei.snowflakemodule.util.PropertyFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Properties;

/**
 * @author hewei
 * @version 1.0
 * @description: 雪花算法实现类
 * @date 2022/10/11 21:26
 */

//@RPCService(value = Snowflake.class)
//@Component
public class SnowflakeImpl implements Snowflake {
    private final SnowflakeWorker snowflakeWorker;

    private SnowflakeImpl() {
        Properties properties = PropertyFactory.getProperties();
        snowflakeWorker = new SnowflakeWorker(IpUtils.getIp(), properties.getProperty(Constants.SNOWFLAKE_PORT));
    }

    @Override
    public synchronized Long getSnowflakeId(String ip, String port) {
        return snowflakeWorker.nextId();
    }
}
